home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pine / ccmd / cmfnc.h4 < prev    next >
Encoding:
Text File  |  1988-08-19  |  9.7 KB  |  299 lines

  1. define(`_',`dnl')_ Use this to prevent extra newlines in the output...
  2. _ ... and for comments!
  3. _
  4. _ Author: Andrew Lowry
  5. _
  6. _ Columbia University Center for Computing Activities, July 1986.
  7. _ Copyright (C) 1986, 1987, Trustees of Columbia University in the
  8. _ City of New York.  Permission is granted to any individual or
  9. _ institution to use, copy, or redistribute this software so long as
  10. _ it is not sold for profit, provided this copyright notice is
  11. _ retained.
  12. _
  13. _
  14. _ * This M4 source is designed to generate two header files for the
  15. _ * ccmd package, based on information for specific parsing functions.
  16. _ * The actual output stream from M4 contains lines of the form:
  17. _ *     #file xxx
  18. _ * flush to the left margin, signaling the beginning of the text for
  19. _ * file xxx.  This output stream can be passed to the split program
  20. _ * in order to distribute the text to the various files.
  21. _ *
  22. _ * The first output file is called cmfnc.h, and contains symbols and
  23. _ * definitions required by application programs that use the ccmd
  24. _ * package.  The second file, cmfncs.h, contains system symbols and
  25. _ * definitions required primarily by the ccmd package modules.
  26. _ *
  27. _ * The last line in this file is an include statement to read in and
  28. _ * process the file cmconf.h4, which should generally be a series of
  29. _ * fndecl statements for bringing in the files describing the various
  30. _ * functions.  For example, the line:
  31. _ *     fndecl(cfm)
  32. _ * in cmconf.h4 would cause the system to be configured with the cmcfm
  33. _ * parsing function.  The line fndecl(xxx) causes an automatic include
  34. _ * of the file cmxxx.h4.
  35. _ *
  36. _ * The files for the individual parse functions generally include the
  37. _ * following items:
  38. _ *
  39. _ *    fnerror(XXX,`error message')
  40. _ *      Causes a symbol such as CFMxXXX to be defined, and causes the
  41. _ *      given error message to be entered into an error table.  The
  42. _ *      prefix is formed from the upper-cased fndecl argument.
  43. _ *
  44. _ *    fnflag(XXX,x)
  45. _ *      Causes a symbol such as CFM_XXX to be defined, with the value x.
  46. _ *      If x is omitted, the value from the prior fnflag invocation is
  47. _ *      doubled.  If this is the first invocation and x is omitted, 1
  48. _ *      is used.  The prior value is cleared by the fndecl macro.
  49. _ *
  50. _ *    fnconst(XXX,x)
  51. _ *      Causes a symbol such as _CFMXXX to be defined, with the value x.
  52. _ *      If x is omitted, the value from the prior fnconst invocation is
  53. _ *      bumped by 1.  If this is the first invocation and x is omitted, 0
  54. _ *      is used.  The prior value is cleared by the fndecl macro.
  55. _ *
  56. _ *    pvtype(type expression)
  57. _ *      Adds a component to the pval union for returned parse values.
  58. _ *      The component will be named something like _pvxxx, where xxx
  59. _ *      is the parse function name.  The component's type will be
  60. _ *      whatever is specified by the type expression.  Parse functions
  61. _ *      that return integers, strings, characters, or floats need not
  62. _ *      include a pvtype line, as components of these types are preloaded.
  63. _ *
  64. _ *    toapplic(`arbitrary text')
  65. _ *      Causes the given text to be included verbatim in the cmfnc.h file.
  66. _ *      Useful for defining special structures and the like.
  67. _ *
  68. _ *    tosystem(`arbitrary text')
  69. _ *      Causes the given text to be included verbatim in the cmfncs.h file.
  70. _ *
  71. _ *    Anything else
  72. _ *      Goes to the cmfnc.h file.
  73. _ *
  74. _
  75. _ Load initial text for each file before defining any macros that might
  76. _ interfere with their contents
  77. _
  78. divert(1)include(`cmfnc.top')
  79. divert(2)include(`cmfncs.top')
  80. _
  81. _ cat returns its arguments concatenated together
  82. _
  83. define(`cat',$1$2$3$4$5$6$7$8$9)_
  84. _
  85. _ nl - represents a newline
  86. _
  87. define(`nl',``
  88. '')_
  89. _
  90. _ quote - Returns its argument with quotes around it
  91. _
  92. define(`quote',`changequote([,])`$1'changequote(`,')')_
  93. _
  94. _ upper and lower convert letters to upper and lower case, resp.
  95. _
  96. define(`lower',`translit($1,`ABCDEFGHIJKLMNOPQRSTUVWXYZ',
  97.               `abcdefghijklmnopqrstuvwxyz')')_
  98. define(`upper',`translit($1,`abcdefghijklmnopqrstuvwxyz',
  99.               `ABCDEFGHIJKLMNOPQRSTUVWXYZ')')_
  100. _
  101. _ fndecl - set up to configure a named parse function (use the 3-char ending
  102. _   from the function name as the argument)
  103. _
  104. define(`fndecl',cat(``divert(1)'',
  105.            ``fnini($1)'',
  106.            ``fncomment()'',
  107.            ``fncode()'',
  108.            ``fnstub()'',
  109.            ``cat(`include(cm',lname,`.cnf)')'',
  110.            ``outerrs()''))_
  111. _
  112. _ fnini - Set variables for a new function configuration
  113. _
  114. define(`fnini',cat(``define(`lname',lower($1))'',
  115.            ``define(`uname',upper($1))'',
  116.            ``define(`lastval',-1)'',
  117.            ``define(`lastflag',0)'',
  118.            ``define(`lasterr',-1)'',
  119.            ``define(`lastfunc',incr(lastfunc))'',
  120.            ``define(`ftlist',
  121.               cat(quote(ftlist),`ftxxx(',lname,`,',lastfunc,`)'))''))_
  122. _
  123. _ fncomment - Output an appropriate comment to each file
  124. _
  125. define(`fncomment',cat(``cat(nl`/* Configuration information for cm',
  126.                 lname,` */',nl,nl)'',
  127.                ``divert(2)'',
  128.                ``cat(nl,`/* Error table and other configuration data',
  129.                 ` for cm',lname,` */',nl,nl)'',
  130.                ``divert(1)''))_
  131. _
  132. _ fncode - Output the function code symbol definition
  133. _
  134. define(`fncode',`cat(``#define _CM'',uname,` ',lastfunc,nl)')_
  135. _
  136. _ fnstub - Output a macro definition to stub out this parse function
  137. _
  138. define(`fnstub',cat(``cat(nl,`/* Macro to prevent loading of cm',
  139.              lname,` support */',nl,nl)'',
  140.             ``cat(`#define ',uname,`_STUB ftspec ft_',lname,
  141.               ` = { NULL, NULL, NULL, 0, NULL }; \',nl)'',
  142.             ``cat(`    fnerr fe_',lname,` = { 0, NULL };',nl,nl)''))_
  143. _
  144. _ fnerror - Used to declare function-specific error messages
  145. _
  146. define(`fnerror',cat(``define(`lasterr',incr(lasterr))'',
  147.              ``divert(3)'',
  148.          ``ifelse(lasterr,0,`',`,')'',
  149.              ``cat(nl,`        "',$2,")'',
  150.              ``divert(1)'',
  151.              ``cat(`#define ',uname,`x',$1,
  152.                 cat(`    CMERR(',lastfunc,`,',lasterr,`)'))''))_
  153. _
  154. _ outerrs - Output the error table declaration and initializer
  155. _
  156. define(`outerrs',cat(``divert(2)'',
  157.              ``define(`lasterr',incr(lasterr))'',
  158.              ``cat(nl,`#ifdef ',uname,`ERR',nl)'',
  159.              ``ifelse(lasterr,0,`outerr1()',`outerr2()')'',
  160.              ``cat(`#else',nl,`extern fnerr fe_',lname,`;',nl)'',
  161.              ``cat(`#endif',nl)'',
  162.              ``divert(1)'',
  163.                  ``_''))_
  164. define(`outerr1',`cat(nl,`fnerr fe_',lname,` = { 0, NULL };',nl)')_
  165. define(`outerr2',cat(nl,
  166.            ``cat(`static char *(',lname,`err[',lasterr,`]) = {')'',
  167.            ``undivert(3)'',
  168.            ``cat(nl,`};',nl)'',
  169.            ``cat(`fnerr fe_',lname,` = { ',
  170.              lasterr,`, ',lname,`err };',nl)''))_
  171. _
  172. _ fnflag - output a flag symbol definition to the cmfnc.h file
  173. _
  174. define(`fnflag',cat(``cat(``#define '',uname,`_',$1,` ')'',
  175.           ``ifelse($2,,
  176.               ifelse(lastflag,0,
  177.             `define(`lastflag',1)',
  178.             `define(`lastflag',eval(2*lastflag))'),
  179.               `define(`lastflag',$2)')'',
  180.            ``hex(lastflag)''))_
  181. _
  182. _ hex - takes a decimal string and outputs it as a four-digit hex value
  183. _ preceded by "0x"
  184. _
  185. define(`hex',`cat(0x,hexx($1))')_
  186. define(`hexx',`cat(hex1(eval($1/4096)),
  187.            hex1(eval(($1-($1/4096)*4096)/256)),
  188.            hex1(eval(($1-($1/256)*256)/16)),
  189.            hex1(eval($1-($1/16)*16)))')_
  190. define(`hex1',`substr(`0123456789abcdef',$1,1)')_
  191. _
  192. _ fnconst - output a constant symbol definition to the cmfnc.h file
  193. _
  194. define(`fnconst',cat(``cat(``#define _'',uname,$1,` ')'',
  195.            ``ifelse($2,,
  196.                `define(`lastval',incr(lastval))',
  197.                `define(`lastval',$2)')'',
  198.             ``cat(lastval)''))_
  199. _
  200. _ pvtype - adds a component to the pval union declaration.  All additions
  201. _ accumulate in diversion 4.
  202. _
  203. define(`pvtype',cat(``divert(4)'',
  204.             ``cat(`        ',$1,` _pv',lname,`;',nl)'',
  205.             ``divert(1)''))_
  206. _
  207. _ toapplic - Output the argument to the cmfnc.h file
  208. _
  209. define(`toapplic',cat(``divert(1)'',`$1'))_
  210. _
  211. _ tosystem - Output the argument to the cmfncs.h file
  212. _
  213. define(`tosystem',cat(``divert(2)'',`$1 ',``nl()'',``divert(1)''))_
  214. _
  215. _ generic - Outputs the generic error codes and error message table.
  216. _ Mostly just a big kludge to invoke the macros called by fndecl after
  217. _ faking the variables.
  218. _
  219. define(`generic',cat(``define(`uname',`CM')'',
  220.              ``define(`lasterr',-1)'',
  221.              ``divert(1)'',
  222.              ``include(cmgnrc.cnf)'',
  223.              ``define(`uname',`GEN')'',
  224.              ``define(`lname',`gen')'',
  225.              ``tosystem(`/* Generic ccmd error messages */')'',
  226.              ``outerrs()''))_
  227. _
  228. _ outlist - Output the function types in ftlist, each prefixed by the
  229. _ first argument and with the column position initialized to the second
  230. _ argument
  231. _
  232. define(`outlist',cat(``define(`ftprefix',$1)'',
  233.              ``define(`ftcolumn',$2)'',
  234.              ``ftlist()''))_
  235. _
  236. _ Initialize function code counter so first code is 1, and set empty fn list
  237. define(`lastfunc',0)_
  238. define(`ftlist',`')_
  239. _
  240. _ OK, here we go...
  241. _
  242. generic
  243. include(cmconf.h4)_
  244. _
  245. _ Now define the ftxxx macro so ftlist will expand correctly into a list
  246. _ of parse function names, each prefixed by the value of ftprefix. 
  247. _ Newlines are inserted when the column counter exceeds 70, with new
  248. _ lines indented two spaces.
  249. _
  250. define(`ftxxx',cat(``define(`ftxxxx',
  251.                cat(ftprefix,$1,ifelse($2,lastfunc,` ',``| '')))'',
  252.            ``define(`ftcolumn',eval(ftcolumn+len(ftxxxx)))'',
  253.            ``translit(ftxxxx,`|',`,')'',
  254.            ``ifelse(eval(ftcolumn > 70),eval(1 > 0),
  255.                cat(nl,`  ',``define(`ftcolumn',2)''))''))_
  256. divert(0)_
  257. #file cmfnc.h
  258. undivert(1)_
  259.  
  260. /* Union declaration for parse return values */
  261.  
  262. typedef union PVAL {
  263.     int _pvint;
  264.     float _pvflt;
  265.     char _pvchr;
  266.     char *_pvstr;
  267.     char **_pvstrvec;
  268. undivert(4)_
  269. } pval;
  270. #file cmfncs.h
  271. undivert(2)_
  272.  
  273. #ifdef STORAGE
  274.  
  275. /* Function handler table */
  276.  
  277. extern ftspec
  278.   outlist(`ft_',2);
  279.  
  280. ftspec *(cmfntb[lastfunc]) = {
  281.   outlist(`&ft_',2)
  282. };
  283.  
  284. /* Error table table */
  285.  
  286. fnerr *(fnetab[eval(lastfunc+1)]) = {
  287.   &fe_gen, outlist(`&fe_',11)
  288. };
  289.  
  290. /* Number of defined functions */
  291.  
  292. int cmfmax = eval(lastfunc+1);
  293.  
  294. #else
  295. extern ftspec *(cmfntb[]);
  296. extern fnerr *(fnetab[]);
  297. extern int cmfmax;
  298. #endif
  299.